import UIKit
import SnapKit
class StatusRetweetedView: UIView {
    //记录底部约束
    
    var bottomConstaint: Constraint?
    
    var retweetedStatus: Status? {
        didSet {
            //设置数据
            retweetedLabel.text = retweetedStatus?.text
            pictureView.imageURLs = retweetedStatus?.imageURLs
            self.bottomConstaint?.uninstall()
            if let imageURLs = retweetedStatus?.imageURLs where imageURLs.count != 0 {
                //转发微博有图
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomConstaint = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                })
            }else {
                //转发微博没有图
              self.snp_makeConstraints(closure: { (make) -> Void in
                  self.bottomConstaint = make.bottom.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin).constraint
              })
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
        addSubview(retweetedLabel)
        addSubview(pictureView)
        //设置约束
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.right.equalTo(self.snp_right).offset(-StatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
        }
        
        //转发微博的地步需要添加约束
        self.snp_makeConstraints { (make) -> Void in
           self.bottomConstaint = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
    }
    
    private lazy var retweetedLabel: UILabel = UILabel(text: "终于等到你", fontSize: 14, textColor: UIColor.darkGrayColor(), alignment: NSTextAlignment.Left)
    
    private lazy var pictureView : StatusPictureView = StatusPictureView()
}
